package org.voidness.squaretilesframework.loaders;

import org.voidness.squaretilesframework.Map;

/**
 * A loader for an old map format Loads maps in the format: mapName width (in
 * tiles) height (int tiles) 0 0 pathToImage 0 1 pathToImage ...
 * 
 */
public class OldMapLoader implements LoaderInterface {
    /**
     * This method loads a map in an old format.
     * 
     * @param mFilename The filename of the map to load
     * @param mTileSize The tile size used in the map
     * @return The newly loaded map
     */
    public Map load(String mFilename, int mTileSize) {
        /*
         * try { // Open a buffer to the file contents BufferedReader dataFile =
         * new BufferedReader(new FileReader(mFilename));
         * 
         * // Read the map name String mapName = dataFile.readLine();
         * 
         * // Read the map's width and height (in tiles) int mapWidth =
         * Integer.parseInt(dataFile.readLine().trim()); int mapHeight =
         * Integer.parseInt(dataFile.readLine().trim());
         * 
         * // Start reading the tiles Map map = new Map(mapWidth, mapHeight);
         * TileSet tileSet = new TileSet(); Tile tiles[][] = new
         * Tile[mapWidth][mapHeight]; String line = null; String[] tileValues =
         * null; while ((line = dataFile.readLine()) != null) { // Split the
         * line using spaces tileValues = line.split(" ");
         * 
         * // Get the tile's X and Y values int x =
         * Integer.parseInt(tileValues[0].trim()); int y =
         * Integer.parseInt(tileValues[1].trim());
         * 
         * // Get whether is animated or not int animated =
         * Integer.parseInt(tileValues[3].trim());
         * 
         * if (animated == 1) { // Search the tileSet for this image name int
         * imageIndex = tileSet.find(tileValues[2].trim()); if (imageIndex > -1)
         * { tiles[x][y] = new Tile(imageIndex, map, false); } else {
         * tileSet.addImage(new GLAnimatedImage(tileValues[2].trim(), mTileSize,
         * mTileSize, mTileSize, mTileSize, 2)); tiles[x][y] = new
         * Tile(tileSet.size()-1, map, false); } } else { // Search the tileSet
         * for this image name int imageIndex =
         * tileSet.find(tileValues[2].trim()); if (imageIndex > -1) {
         * tiles[x][y] = new Tile(imageIndex, map, false); } else {
         * tileSet.addImage(new GLImage(tileValues[2].trim(), mTileSize,
         * mTileSize, false)); tiles[x][y] = new Tile(tileSet.size()-1, map,
         * false); } } }
         * 
         * map.setName(mapName); map.setTiles(tiles); map.setTileSet(tileSet);
         * 
         * // Return the new map return map; } catch (FileNotFoundException e) {
         * Utils.dump("Map file not found: " + mFilename, Utils.ERROR);
         * System.exit(1); } catch (IOException e) {
         * Utils.dump("Error reading map file: " + mFilename, Utils.ERROR);
         * System.exit(1); }
         * 
         * // If we got here, some wicked stuff happened
         * Utils.dump("Strange error reading map file: " + mFilename,
         * Utils.ERROR); System.exit(1);
         */
        return null;
    }
}